package com.glory.brepda.activity.mfg;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.glory.brepda.R;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.callback.CustomDialogEntityCallBack;
import com.glory.brepda.entity.n2CabinetEntity;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import butterknife.BindView;
import butterknife.OnClick;

public class N2CabinetOutActivity extends BaseActivity {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.tvLotId)
    FreeUI_ClearEditText tvLotId;

    private String Statu="";


    @Override
    protected int getLayoutResId() {
        return R.layout.activity_n2_cabinet_out;
    }

    @Override
    protected void initView() {
        setMainLayout(llMain);
        tvTitle.setText("氮气柜出柜");
        tvBaseSubmit.setText("出柜");
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.tvBaseSubmit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvBaseSubmit:
//                if (actionControl("DownLoad04"))
//                    return;

                if (getText(tvLotId).equals("") ) {
                    showToast("批次号不能为空", false);
                    return;
                }
                submit();
                break;
        }
    }

    private void submit() {
        FreeUI_EntityCallBack<BaseResponseBean<n2CabinetEntity>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<n2CabinetEntity>>
                (new TypeToken<BaseResponseBean<n2CabinetEntity>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess(Response<BaseResponseBean<n2CabinetEntity>> response) {
                super.onSuccess(response);
//                showToast(response.body().getResponse().getBody().getPROMPT(), false);
                // 弹窗提示
                Context context = getApplicationContext();
                Toast toast = Toast.makeText(context, response.body().getResponse().getBody().getPROMPT(), Toast.LENGTH_SHORT);
                toast.show();

            }

            @Override
            public void onError(Response<BaseResponseBean<n2CabinetEntity>> response) {
                super.onError(response);
                // 弹窗提示
//                Context context = getApplicationContext();
//                Toast toast = Toast.makeText(context, response.body().getResponse().getBody().getPROMPT(), Toast.LENGTH_SHORT);
//                toast.show();
                showToast(response.body().getResponse().getBody().getPROMPT(), false);
                loadError(response.getException(), "GetEquipment");
            }
        };

        JsonObject map = new JsonObject();
        map.addProperty("LOTID",getText(tvLotId));
        map.addProperty("ACTIONTYPE","OUT");
        NetUtils.requestPostNet("IF.BREN2CABINET","Common", N2CabinetOutActivity.this,map,callBack);
    }
}
